package chapter7.test.no4;

import java.util.Scanner;

public class Main {
    public static Animal getAnimal(){
        String kind;
        Scanner scanner=new Scanner(System.in);
        System.out.println("Which kind of animals dou you want to discover?");
        kind=scanner.next();
        Animal animal;


        if(kind.equals("Bird"))
            animal=new Bird();
        else if (kind.equals("Fish")) {
            animal=new Fish();
        }
        else return null;
        return animal;
    }
    public static void main(String[] args) {
        Animal animal=getAnimal();
        animal.action();
    }
}
class Animal{
    void communication(){
        System.out.println("all animals have their unique way of communication");
    }
    void action(){
        this.communication();
        System.out.println("eating");
        System.out.println("sleeping");
    }
}
class Bird extends Animal{
    @Override
    void communication() {
        System.out.println("Bird communicates through tweeting");
    }
}
class Fish extends Animal{
    @Override
    void communication() {
        System.out.println("Fish communicates through bubbling");
    }
}